package com.develop.wechatpay.controller.base;

import cn.hutool.core.util.XmlUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.develop.wechatpay.domain.WechatPayWSModelRe;
import com.develop.wechatpay.mapper.base.WSMapper;
import com.develop.wechatpay.service.base.UserService;
import com.develop.wechatpay.util.HttpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

//@RestController
//@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private WSMapper wsMapper;

    @GetMapping("/list")
    public List<Map<String, Object>> selectUserList() {
        return userService.selectUserList();
    }

    @PostMapping("/demo")
    public String insertWSWeChatPayReLog(HttpServletRequest request, HttpServletResponse response) {
        String body = HttpUtils.readData(request);
        Map<String, Object> mapXml = XmlUtil.xmlToMap(body);
        WechatPayWSModelRe wechatPayWSModelRe = JSONUtil.toBean(JSONUtil.parseObj(mapXml), WechatPayWSModelRe.class);
        wechatPayWSModelRe.setFWSTZXml(body);
        String logId = wsMapper.insertWSWeChatPayReLog(wechatPayWSModelRe);
        return logId;
    }
}
